package com.jintian.smart.kernel.flowable.flowable.service.impl;

import com.jintian.smart.kernel.flowable.engine.BaseProcessService;
import com.jintian.smart.kernel.flowable.flowable.service.IProcessQuery;
import org.flowable.engine.runtime.ProcessInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 流程实例查询
 */
@Component
public class InstanceQueryHandler extends BaseProcessService implements IProcessQuery {
    protected static Logger logger = LoggerFactory.getLogger(InstanceQueryHandler.class);

    @Override
    public ProcessInstance processInstanceId(String processInstanceId) {
        return processInstanceQuery().processInstanceId(processInstanceId).singleResult();
    }

    @Override
    public ProcessInstance processInstanceBusinessKey(String processInstanceBusinessKey) {
        return processInstanceQuery().processInstanceBusinessKey(processInstanceBusinessKey).singleResult();
    }

    @Override
    public boolean hasProcessInstanceFinished(String processInstanceId) {
        ProcessInstance pi = processInstanceId(processInstanceId);
        return pi == null;
    }
}
